package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.zzyl.dto.BedDto;
import com.zzyl.entity.Bed;
import com.zzyl.enums.BasicEnum;
import com.zzyl.exception.BaseException;
import com.zzyl.mapper.BedMapper;
import com.zzyl.service.BedService;
import com.zzyl.vo.BedVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class BedServiceImpl implements BedService {

    @Autowired
    private BedMapper bedMapper;

    @Override
    public List<BedVo> getBedsByRoomId(Long roomId) {
        return bedMapper.getBedsByRoomId(roomId);
    }


    @Override
    public int addBed(BedDto bedDto) {
        //TODO 是否需要重判断

            Bed bed = BeanUtil.copyProperties(bedDto, Bed.class);
            bed.setBedStatus(0);//默认床位入住状态为 0:未入住
            return bedMapper.insertBed(bed);

    }

    /**
     * 根据id删除床位
     * @param id 床位id
     * @return 删除记录数
     */
    @Override
    public int deleteById(Long id) {
        //TODO 该床位有人不能删
        return bedMapper.deleteBedByid(id);
    }

    /**
     * 根据id查询床位
     * @param id 床位id
     * @return 床位信息
     */
    @Override
    public BedVo queryBedById(Long id) {
        Bed bed = bedMapper.queryBedById(id);
        BedVo bedVo = BeanUtil.copyProperties(bed, BedVo.class);
        return bedVo;
    }

    /**
     * 更新床位
     * @param 床位信息
     * @return
     */
    @Override
    public int updateBad(BedDto bedDto) {
        Bed bed = BeanUtil.copyProperties(bedDto, Bed.class);
        return bedMapper.updateBed(bed);
    }

}

